package com.deprecated.patch;

import javax.swing.JCheckBox;

import com.panopset.java.Version;
import com.panopset.sf.FontManager.FontType;
import com.panopset.sf.Windoc;

/**
 * JCheckBox persistent container.
 *
 * @author Karl Dinwiddie
 *
 */
public final class PanCheckBox extends PanNoBorderField<JCheckBox> {

    private final String lbl;

    /**
     * @param label
     *            Label.
     * @param toolTipText
     *            Tool tip text.
     */
    public PanCheckBox(final Windoc wd, final String label, final String toolTipText) {
        super(wd, Boolean.FALSE.toString(), toolTipText);
        lbl = label;
        setFieldGui(new FieldGui() {

            @Override
            public String getValue() {
                return Boolean.valueOf(getInnerComponent().isSelected())
                        .toString();
            }

            @Override
            public void setValue(final String value) {
                getInnerComponent().setSelected(Boolean.parseBoolean(value));
            }
        });
    }

    /**
     * Create a Panopset checkbox with no tool tip text.
     *
     * @param title
     *            Title.
     */
    public PanCheckBox(final Windoc wd, final String title) {
        this(wd, title, "");
    }

    @Override
    public JCheckBox createComponent() {
        JCheckBox rtn = new JCheckBox(lbl);
        rtn.setBackground(LookAndFeel.Colors.BG_COLOR.getColor());
        fm.register(rtn, FontType.plainArial);
        return rtn;
    }

    /**
     * Serial version id.
     */
    private static final long serialVersionUID = Version.UNI_VERSION;


    @Override
    protected boolean isValid(final String valueToCheck) {
        return true;
    }

    /**
     * @return True iff user checked this box.
     */
    public boolean isChecked() {
        return getInnerComponent().isSelected();
    }
}
